<?php
class CF_ProcessorCrud extends CF_ProcessorBase {
var $crud;

function set_crud_class(&$crud){
	global $DataSourceSet;	
	//$this->crud = &$DataSourceSet['employees'];
	$this->crud = $crud;

}

function test_crud(){
	print "The CRUD Class is " . $this->crud->tell_class();
}

/*
Options for variable input (methods, use $this->):
Single Value, through name and value parameter: GetSingleValue($varParam = 'var',$valParam = 'value')
url parameters:  GetReqParamsByList($list,[<prefix>],[<require all in list :true,false]>
Packed Parameters, one set: GetPackedParamValues(<VariableNameParameter>, <PackedValueParameter>)
Packed Parameters, multiple sets: GetPackedParamValues(<VariableNameParameter>, <PackedSetsParameter>)

Packed parameters values delimited by $this->value_adelimiter
Packed parameter sets delimited by $this->set_delimiter

Functions for limiting value sets:
FilterByList(&$TargetList, $LimitList)
CheckArrayComplete($TargetList, $LimitList)

Fieldspec info:
keys list in $this->$keyvarslist
columns list in $this->colvarslist


*/

		// construct function names for operation
		
	// ----------------  Operation: Save
		function get_flt_Save(){
		
		}		
		function get_keys_Save(){
			$this->keyvalues = $this->GetReqParamsByList($this->keyvarslist,'',true);		
		}
		function get_new_Save(){
			$this->newvalues = $this->GetReqParamsByList($this->colvarslist,'',false);		
		}
		//function get_old_Save(){}
		//function get_ctl_Save(){}			
		function process_Save(){
			echo '<pre>';
			print_r($this->newvalues);
			echo '<pre />';
		
		}
		//function after_Save(){}
		//function on_pre_Save(){}
		//function on_post_Save(){}		
		//function on_error_Save(){}	
	
	// ----------------  Operation: Delete
		
		function get_keys_Delete(){
			$this->keyvalues = $this->GetReqParamsByList($this->keyvarslist,'',true);
		}
		function process_Delete(){
			$this->crud->CrudDelete();
		}
		function after_Delete(){
			$header_text = "Location: {$_SERVER['PHP_SELF']}"; 
			header($header_text); /* Redirect browser */ 
		}
		//function on_error_Delete(){}	

	// ----------------  Operation: Add
		function get_flt_Add(){
		
		}		
		function get_keys_Add(){
		
		}
		function get_new_Add(){
		
		}
		//function get_old_Add(){}
		//function get_ctl_Add(){}			
		function process_Add(){
			$this->newvalues = $this->GetReqParamsByList($this->colvarslist,'',false);
			
			$this->crud->CrudNew();
		
		}
		//function after_Add(){}
		//function on_pre_Add(){}
		//function on_post_Add(){}		
		//function on_error_Add(){}			

		// ----------------  Operation: Change
		
		function get_flt_Change(){
		
		}		
		function get_keys_Change(){
			$this->keyvalues = $this->GetReqParamsByList($this->keyvarslist,'',true);		
		}
		function get_new_Change(){
			$this->newvalues = $this->GetReqParamsByList($this->colvarslist,'',false);		
		}
		//function get_old_Change(){}
		//function get_ctl_Change(){}			
		function process_Change(){
			print_r($this->keyvarslist);
			print_r($this->colvarslist);
			print '<pre> keyvalues';
			print_r($this->keyvalues);			
			echo 'newvalues';
			print_r($this->newvalues);
			echo '<pre />';
			$this->crud->CrudSave();
		}
		
		function after_Change(){
		echo 'Saved';
		}
		
		// ----------------  Operation: update
		function get_flt_update(){
		
		}		
		function get_keys_update(){
			$this->keyvalues = $this->GetPackedParamValues($varParam = 'ks',$valParam = 'kv');

		}
		function get_new_update(){
			$this->newvalues = $this->GetSingleValue($varParam = 'field',$valParam = 'value');
		}
		//function get_old_update(){}
		//function get_ctl_update(){}			
		function process_update(){
		
		$this->crud->CrudSave();
		}
		function after_update(){
			$result ['status'] = $this->status;
			if(empty($this->is_error)){
				$result['status'] = 'OK';
				$result['msg'] = 'OK';
				
			}else{
				$result['status'] = 'Error';
				$result['msg'] = $this->status;				
			}
		echo json_encode($result);	
		}
		//function on_pre_update(){}
		//function on_post_update(){}		
		//function on_error_update(){}	

		// ----------------  Operation: list
		function get_flt_list(){
		
		}		
		function get_keys_list(){
		
		}
		function get_new_list(){
		
		}
		//function get_old_list(){}
		//function get_ctl_list(){}			
		function process_list(){
		
		
		}
		//function after_list(){}
		//function on_pre_list(){}
		//function on_post_list(){}		
		//function on_error_list(){}	

		
		
		
}

?>
